﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Web.Mvc;

namespace HitchHikersGuideToTheGalaxy.Models
{
    [Bind(Include = "Id,TourId,UserInfoSSN,Accepted,Cost")]
    public partial class Passenger
    {
        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }

        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (String.IsNullOrEmpty(Id.ToString()))
                yield return new RuleViolation("Id is required", "Id");

            if (String.IsNullOrEmpty(TourId.ToString()))
                yield return new RuleViolation("TourId is required", "TourId");

            if (String.IsNullOrEmpty(UserInfoSSN))
                yield return new RuleViolation("UserInfoSSN is required", "UserInfoSSN");

            if (String.IsNullOrEmpty(Accepted.ToString()))
                yield return new RuleViolation("Accepted is required", "Accepted");

            if (String.IsNullOrEmpty(Cost.ToString()))
                yield return new RuleViolation("Cost is required", "Cost");

            yield break;
        }

        partial void OnValidate(ChangeAction action)
        {
            if (!IsValid)
                throw new ApplicationException("Rule violations prevent saving");
        }
    }
}
